package com.bdqn.service.impl;

import com.bdqn.entity.StorageRecord;
import com.bdqn.mapper.StorageRecordMapper;
import com.bdqn.service.StorageRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("storageRecordService")
public class StorageRecordServiceImpl implements StorageRecordService {
    @Autowired
    private StorageRecordMapper storageRecordMapper;

    @Override
    public List<StorageRecord> findAll(StorageRecord storageRecord) {
        return storageRecordMapper.getRecord(storageRecord);
    }

    @Override
    @Transactional
    public int saveBatch(List<StorageRecord> storageRecord) {
        int rows = 0;
        for (int i = 0; i < storageRecord.size(); i++) {
            StorageRecord record = storageRecord.get(i);
            rows += storageRecordMapper.insert(record);
        }
        return rows;
    }

    @Override
    @Transactional
    public int updateBatch(List<StorageRecord> storageRecord) {
        int rows = 0;
        for (int i = 0; i < storageRecord.size(); i++) {
            StorageRecord record = storageRecord.get(i);
            rows += storageRecordMapper.update(record);
        }
        return rows;
    }

    @Override
    @Transactional
    public int deleteBatch(List<Long> idList) {
        int rows = 0;
        for (int i = 0; i < idList.size(); i++) {
            Long id = idList.get(i);
            rows += storageRecordMapper.delete(id);
        }
        return rows;
    }

    public void setStorageRecordMapper(StorageRecordMapper storageRecordMapper) {
        this.storageRecordMapper = storageRecordMapper;
    }
}
